package Presentacion.academico;

import global.Iconos;
import javax.swing.DefaultListModel;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

public final class dlgAsignacionCursoMateriaDocente extends javax.swing.JDialog {

    private DefaultListModel modelomateria;
    private DefaultTableModel modelo;
    private Iconos ico = new Iconos();

    public dlgAsignacionCursoMateriaDocente(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        setTitle("ASIGNACION DE MATERIAS Y CURSOS A LOS DOCENTES");
        setLocationRelativeTo(this);
        iconos();
        setResizable(false);
        frmConsultaMateriaCursoDocente.objMateriaDocente.curso.listarCursoActivoCombo(cboCurso);
        frmConsultaMateriaCursoDocente.objMateriaDocente.docente.listarDocentes(cboDocente);
        visiblidad(true);
        iniciar();
        hablitarBotones();

    }
    private void iconos() {
        btnnuevo.setIcon(ico.getNuevo());
        btnguardar.setIcon(ico.getGuardar());
        btnsalir.setIcon(ico.getSalir());
        btnactualizar.setIcon(ico.getActualizar());
    }

    private void armarmodelo() {
        modelo = new DefaultTableModel() {
            @Override
            public boolean isCellEditable(int fila, int columna) {
                return columna == 2;
            }
        };
        tblDocente.removeAll();
        tblDocente.setModel(modelo);
        modelo.addColumn("MATERIA");
        modelo.addColumn("CURSO");
        modelo.addColumn("HORAS");

        DefaultTableCellRenderer centrar = new DefaultTableCellRenderer();
        centrar.setHorizontalAlignment(SwingConstants.CENTER);
        tblDocente.getColumnModel().getColumn(2).setCellRenderer(centrar);
        TableColumn columna = new TableColumn();
        columna = tblDocente.getColumnModel().getColumn(0);
        columna.setPreferredWidth(300);
        columna = tblDocente.getColumnModel().getColumn(1);
        columna.setPreferredWidth(300);
    }

    private void iniciar() {
        cboCurso.setSelectedIndex(0);
        cboDocente.setSelectedIndex(0);
        limpiarModelo();
        armarmodelo();
    }

    private void limpiarModelo() {
        modelomateria = new DefaultListModel();
        lMateria.setModel(modelomateria);
    }

    public void visiblidad(boolean visibilidad) {
        if (visibilidad != true) {
            btnactualizar.setVisible(true);
            btnguardar.setVisible(false);
        } else {
            btnactualizar.setVisible(false);
            btnguardar.setVisible(true);
        }
    }

    private void hablitarBotones() {
        if ((cboCurso.getSelectedIndex() != 0) && (cboDocente.getSelectedIndex() != 0)) {

            btnpasar.setEnabled(true);
            btnpasartodo.setEnabled(true);
            btnregresar.setEnabled(true);
            btnregresartodo.setEnabled(true);
            lMateria.setEnabled(true);
            tblDocente.setEnabled(true);
            btnactualizar.setEnabled(true);
            btnguardar.setEnabled(true);

        } else {
            btnpasar.setEnabled(false);
            btnpasartodo.setEnabled(false);
            btnregresar.setEnabled(false);
            btnregresartodo.setEnabled(false);
            lMateria.setEnabled(false);
            tblDocente.setEnabled(false);
            btnactualizar.setEnabled(false);
            btnguardar.setEnabled(false);
        }
    }

    private boolean ExitenciaAgregar() {
        int j = tblDocente.getRowCount();
        for (int i = 0; i < j; i++) {
            if (cboCurso.getSelectedItem().toString().equals(tblDocente.getValueAt(i, 1).toString())
                    && lMateria.getSelectedValue().toString().equals(tblDocente.getValueAt(i, 0).toString())) {
                return true;
            }
        }
        return false;
    }

    private boolean ExitenciaQuitar() {
        int j = modelomateria.size();
        for (int i = 0; i < j; i++) {
            if (cboCurso.getSelectedItem().toString().equals(tblDocente.getValueAt(tblDocente.getSelectedRow(), 1).toString())
                    && lMateria.getModel().getElementAt(i).toString().equals(tblDocente.getValueAt(tblDocente.getSelectedRow(), 0).toString())) {
                return true;
            }
        }
        return false;
    }

    private void Agregar() {
        String[] fila = new String[3];
        fila[0] = lMateria.getSelectedValue().toString();
        fila[1] = cboCurso.getSelectedItem().toString();
        fila[2] = "1";
        modelo.addRow(fila);
        modelomateria.removeElementAt(lMateria.getSelectedIndex());
        lMateria.setSelectedIndex(0);
        tblDocente.getSelectionModel().setSelectionInterval(0, 0);
    }

    private boolean guardarAsignacion() {
        int total = modelo.getRowCount();
        int t = modelomateria.size();
        int s = 0;

        for (int j = 0; j < t; j++) {
            lMateria.setSelectedIndex(j);
            if (frmConsultaMateriaCursoDocente.objMateriaDocente.ExistenciaAsignacionDocente(cboCurso.getSelectedItem().toString(),
                    lMateria.getSelectedValue().toString(), cboDocente.getSelectedItem().toString()) == true) {
                frmConsultaMateriaCursoDocente.objMateriaDocente.eliminarMateriaDocente(cboCurso.getSelectedItem().toString(),
                        lMateria.getSelectedValue().toString(), cboDocente.getSelectedItem().toString());
            }

        }

        for (int i = 0; i < total; i++) {
            tblDocente.getSelectionModel().setSelectionInterval(i, 0);
            frmConsultaMateriaCursoDocente.objMateriaDocente.docente.sacarCedulaDocente(cboDocente.getSelectedItem().toString());
            frmConsultaMateriaCursoDocente.objMateriaDocente.sacarIdMateriaPeriodoCurso(tblDocente.getValueAt(i, 0).toString(), tblDocente.getValueAt(i, 1).toString());
            frmConsultaMateriaCursoDocente.objMateriaDocente.setHoras(Integer.parseInt(modelo.getValueAt(i, 2).toString()));
            if (frmConsultaMateriaCursoDocente.objMateriaDocente.ExistenciaAsignacionDocente(tblDocente.getValueAt(i, 1).toString(),
                    tblDocente.getValueAt(i, 0).toString(), cboDocente.getSelectedItem().toString()) == false) {
                
               if (frmConsultaMateriaCursoDocente.objMateriaDocente.guardarMateriaDocente() == false) {
                    s++;
                }
            } else {
                frmConsultaMateriaCursoDocente.objMateriaDocente.sacarIdmateriaDocente(cboCurso.getSelectedItem().toString(),
                        tblDocente.getValueAt(i, 0).toString(), cboDocente.getSelectedItem().toString());
                if (frmConsultaMateriaCursoDocente.objMateriaDocente.actualizarMateriaDocente() == false) {
                    s++;
                }
            }
        }

        if (s == 0) {
            frmConsultaMateriaCursoDocente.generartabla();
            return true;
        } else {
            return false;
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar4 = new javax.swing.JToolBar();
        btnnuevo = new javax.swing.JButton();
        btnguardar = new javax.swing.JButton();
        btnactualizar = new javax.swing.JButton();
        btnsalir = new javax.swing.JButton();
        panelCurso = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        lMateria = new javax.swing.JList();
        btnpasartodo = new javax.swing.JButton();
        btnpasar = new javax.swing.JButton();
        btnregresar = new javax.swing.JButton();
        btnregresartodo = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        cboCurso = new javax.swing.JComboBox();
        jScrollPane3 = new javax.swing.JScrollPane();
        tblDocente = new javax.swing.JTable();
        jLabel3 = new javax.swing.JLabel();
        cboDocente = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        jToolBar4.setBorder(null);
        jToolBar4.setFloatable(false);
        jToolBar4.setBorderPainted(false);

        btnnuevo.setText("Nuevo");
        btnnuevo.setFocusable(false);
        btnnuevo.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnnuevo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnnuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnnuevoActionPerformed(evt);
            }
        });
        jToolBar4.add(btnnuevo);

        btnguardar.setText("Guardar");
        btnguardar.setFocusable(false);
        btnguardar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnguardar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnguardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnguardarActionPerformed(evt);
            }
        });
        jToolBar4.add(btnguardar);

        btnactualizar.setText("Actulizar");
        btnactualizar.setFocusable(false);
        btnactualizar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnactualizar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnactualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnactualizarActionPerformed(evt);
            }
        });
        jToolBar4.add(btnactualizar);

        btnsalir.setText("Salir");
        btnsalir.setFocusable(false);
        btnsalir.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnsalir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnsalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnsalirActionPerformed(evt);
            }
        });
        jToolBar4.add(btnsalir);

        panelCurso.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jScrollPane1.setViewportView(lMateria);

        btnpasartodo.setText(">>");
        btnpasartodo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnpasartodoActionPerformed(evt);
            }
        });

        btnpasar.setText(">");
        btnpasar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnpasarActionPerformed(evt);
            }
        });

        btnregresar.setText("<");
        btnregresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnregresarActionPerformed(evt);
            }
        });

        btnregresartodo.setText("<<");
        btnregresartodo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnregresartodoActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel2.setText("CURSO");

        cboCurso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboCursoActionPerformed(evt);
            }
        });

        tblDocente.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane3.setViewportView(tblDocente);

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel3.setText("DOCENTE");

        cboDocente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboDocenteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelCursoLayout = new javax.swing.GroupLayout(panelCurso);
        panelCurso.setLayout(panelCursoLayout);
        panelCursoLayout.setHorizontalGroup(
            panelCursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelCursoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelCursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelCursoLayout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cboCurso, javax.swing.GroupLayout.PREFERRED_SIZE, 286, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelCursoLayout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 338, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelCursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(panelCursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(btnregresar, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(btnregresartodo))
                            .addComponent(btnpasar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnpasartodo, javax.swing.GroupLayout.Alignment.TRAILING))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelCursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelCursoLayout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cboDocente, javax.swing.GroupLayout.PREFERRED_SIZE, 360, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 547, Short.MAX_VALUE)))
        );
        panelCursoLayout.setVerticalGroup(
            panelCursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelCursoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelCursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelCursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(cboCurso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelCursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(cboDocente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(panelCursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelCursoLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(panelCursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 428, Short.MAX_VALUE))
                        .addContainerGap())
                    .addGroup(panelCursoLayout.createSequentialGroup()
                        .addGap(153, 153, 153)
                        .addComponent(btnpasartodo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnpasar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnregresar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnregresartodo)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jToolBar4, javax.swing.GroupLayout.PREFERRED_SIZE, 875, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 85, Short.MAX_VALUE))
                    .addComponent(panelCurso, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(3, 3, 3)
                .addComponent(jToolBar4, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelCurso, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        panelCurso.getAccessibleContext().setAccessibleName("Asignar Especiales");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnnuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnnuevoActionPerformed
        iniciar();
        visiblidad(true);

    }//GEN-LAST:event_btnnuevoActionPerformed

    private void btnguardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnguardarActionPerformed
        if (guardarAsignacion() == true) {
            global.Dialogos.GuardadoconExito();
            iniciar();
        } else {
            global.Dialogos.Error("Error al asignar el docente");
        }
    }//GEN-LAST:event_btnguardarActionPerformed

    private void btnactualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnactualizarActionPerformed
        if (guardarAsignacion() == true) {
            global.Mensajes.mostrarMensaje("Correcto!", "Datos actualizados correctamente...!", 1);
            dispose();
            iniciar();
        } else {
            global.Dialogos.Error("Error al actualizar los datos");
        }
    }//GEN-LAST:event_btnactualizarActionPerformed

    private void btnsalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnsalirActionPerformed
        dispose();
        iniciar();
        visiblidad(true);

    }//GEN-LAST:event_btnsalirActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        iniciar();
    }//GEN-LAST:event_formWindowClosed

    private void btnpasartodoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnpasartodoActionPerformed
        int j = modelomateria.size();
        int a = 0;
        if (modelomateria.isEmpty() != true) {
            for (int i = 0; i < j; i++) {
                if (ExitenciaAgregar() == true) {
                    a++;
                    if (i < j) {
                        lMateria.setSelectedIndex(i + 1);
                    }
                } else {
                    Agregar();
                }
            }
            if (a != 0) {
                global.Mensajes.mostrarMensaje("Advertencia!", "Una o varias materia ya estan agregada", 3);
            }
        } else {
            global.Mensajes.mostrarMensaje("Advertencia!", "No hay materias para asignar", 3);
        }
    }//GEN-LAST:event_btnpasartodoActionPerformed

    private void btnpasarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnpasarActionPerformed
        if (modelomateria.isEmpty() != true) {
            System.out.println("sssss");
            if (ExitenciaAgregar() == true) {
                global.Mensajes.mostrarMensaje("Advertencia!", "Esta materia ya esta agregada", 3);
            } else {
                Agregar();
            }
        } else {
            global.Mensajes.mostrarMensaje("Materia", "No hay materias para asignar", 3);
        }
    }//GEN-LAST:event_btnpasarActionPerformed

    private void btnregresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnregresarActionPerformed
        if (modelo.getRowCount() != 0) {
            if (cboCurso.getSelectedItem().toString().equals(tblDocente.getValueAt(tblDocente.getSelectedRow(), 1).toString())) {
                if (ExitenciaQuitar() == true) {
                    modelo.removeRow(tblDocente.getSelectedRow());
                    tblDocente.getSelectionModel().setSelectionInterval(0, 0);
                } else {
                    modelomateria.addElement(tblDocente.getValueAt(tblDocente.getSelectedRow(), 0));
                    lMateria.setModel(modelomateria);
                    modelo.removeRow(tblDocente.getSelectedRow());
                    lMateria.setSelectedIndex(0);
                    tblDocente.getSelectionModel().setSelectionInterval(0, 0);
                }
            } else {
                global.Mensajes.mostrarMensaje("Advertencia!", "Esta materia no pertenece al Curso " + cboCurso.getSelectedItem().toString() + "", 3);
            }
        } else {
            global.Mensajes.mostrarMensaje("Error", "No hay materias asignadas", 3);
        }
    }//GEN-LAST:event_btnregresarActionPerformed

    private void btnregresartodoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnregresartodoActionPerformed
        if (modelo.getRowCount() != 0) {
            int j = modelo.getRowCount();

            for (int i = 0; i < j; i++) {
                if (cboCurso.getSelectedItem().toString().equals(tblDocente.getValueAt(tblDocente.getSelectedRow(), 1).toString())) {
                    if (ExitenciaQuitar() == true) {
                        modelo.removeRow(tblDocente.getSelectedRow());
                        tblDocente.getSelectionModel().setSelectionInterval(0, 0);
                    } else {
                        modelomateria.addElement(tblDocente.getValueAt(tblDocente.getSelectedRow(), 0));
                        lMateria.setModel(modelomateria);
                        //modelo.removeRow(tblDocente.getSelectedRow());
                        lMateria.setSelectedIndex(0);
                        // tblDocente.getSelectionModel().setSelectionInterval(0, 0);
                    }
                } else {
                    global.Mensajes.mostrarMensaje("Advertencia!", "Esta materia no pertenece al Curso " + cboCurso.getSelectedItem().toString() + "", 3);
                    return;
                }
            }
        } else {
            global.Mensajes.mostrarMensaje("Error", "No hay materias asignadas", 3);
        }
    }//GEN-LAST:event_btnregresartodoActionPerformed

    private void cboCursoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboCursoActionPerformed
        if (cboCurso.getSelectedIndex() != 0) {
            limpiarModelo();
            frmConsultaMateriaCursoDocente.objMateriaDocente.listaMateriaNoAsignadaDocente(lMateria, modelomateria, cboCurso.getSelectedItem().toString());
            hablitarBotones();

        } else {
            hablitarBotones();
        }
    }//GEN-LAST:event_cboCursoActionPerformed

    private void cboDocenteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboDocenteActionPerformed
        if (cboDocente.getSelectedIndex() == 0) {
            hablitarBotones();
        } else {
            hablitarBotones();
            armarmodelo();
            frmConsultaMateriaCursoDocente.objMateriaDocente.listaMateriaAsignadaDocente(tblDocente, modelo, cboDocente.getSelectedItem().toString());
        }
    }//GEN-LAST:event_cboDocenteActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(dlgAsignacionCursoMateriaDocente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                dlgAsignacionCursoMateriaDocente dialog = new dlgAsignacionCursoMateriaDocente(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnactualizar;
    private javax.swing.JButton btnguardar;
    private javax.swing.JButton btnnuevo;
    private javax.swing.JButton btnpasar;
    private javax.swing.JButton btnpasartodo;
    private javax.swing.JButton btnregresar;
    private javax.swing.JButton btnregresartodo;
    private javax.swing.JButton btnsalir;
    public javax.swing.JComboBox cboCurso;
    public javax.swing.JComboBox cboDocente;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JToolBar jToolBar4;
    private javax.swing.JList lMateria;
    private javax.swing.JPanel panelCurso;
    private javax.swing.JTable tblDocente;
    // End of variables declaration//GEN-END:variables
}
